Add opaque metadata passthrough to SDK tool definitions#1864
Merged
stephentoub merged 11 commits intoJul 15, 2026
Conversation
stephentoub
reviewed
Jul 1, 2026
belaltaher8
force-pushed
the
belaltaher8/tool-meta-passthrough
branch
2 times, most recently
from
July 8, 2026 01:04
68c607d to
6fdc349
Compare
metadata passthrough to SDK tool definitions
belaltaher8
marked this pull request as ready for review
July 8, 2026 01:54
Contributor
There was a problem hiding this comment.
Pull request overview
Adds an optional, opaque metadata bag to tool definitions across the multi-language SDKs and forwards it verbatim over session.create / session.resume, enabling hosts to attach namespaced, runtime-recognized (but SDK-opaque) attributes without expanding the typed contract.
Changes:
- Add
metadatato tool definition types/builders (Rust/Go/Node/Python/.NET/Java) with “omit when unset” behavior where applicable. - Wire
metadatathrough session create/resume payload construction (Node + Python shown here; others rely on serialization of the definition type). - Add/extend unit tests to validate serialization and omission semantics; update Java annotation-processor fixtures for the new constructor arity.
Show a summary per file
| File | Description |
|---|---|
| rust/src/types.rs | Add Tool.metadata, builder, Debug output, and serialization test. |
| python/copilot/tools.py | Add Tool.metadata + define_tool(..., metadata=...) passthrough. |
| python/copilot/client.py | Include metadata when building tool definitions for create/resume RPCs. |
| python/test_client.py | Add test asserting metadata forwarded on create/resume and omitted when unset. |
| nodejs/src/types.ts | Extend Tool / defineTool types to include optional metadata. |
| nodejs/src/client.ts | Forward tool.metadata into session.create / session.resume payloads. |
| nodejs/test/client.test.ts | Add tests for forwarding and omission of metadata. |
| go/types.go | Add Tool.Metadata with omitempty JSON tag. |
| go/client_test.go | Add serialization tests for tool metadata presence/omission. |
| dotnet/src/CopilotTool.cs | Add MetadataKey + option plumbing into AITool.AdditionalProperties. |
| dotnet/src/Client.cs | Include metadata in internal wire ToolDefinition built from AI function declarations. |
| dotnet/test/Unit/CopilotToolTests.cs | Add unit tests ensuring metadata is set/omitted in additional properties. |
| java/src/main/java/com/github/copilot/rpc/ToolDefinition.java | Add metadata record component + factories + fluent modifier. |
| java/src/main/java/com/github/copilot/tool/CopilotToolProcessor.java | Emit null metadata argument in generated ToolDefinition(...) calls. |
| java/src/test/java/com/github/copilot/ToolDefinitionTest.java | Add serialization tests for metadata presence/omission. |
| java/src/test/java/com/github/copilot/rpc/fixtures/StaticTools$$CopilotToolMeta.java | Update fixture constructor call to include null metadata arg. |
| java/src/test/java/com/github/copilot/rpc/fixtures/StaticInvocationTools$$CopilotToolMeta.java | Update fixture constructor call to include null metadata arg. |
| java/src/test/java/com/github/copilot/rpc/fixtures/SimpleTools$$CopilotToolMeta.java | Update fixture constructor calls to include null metadata arg. |
| java/src/test/java/com/github/copilot/rpc/fixtures/OverrideTools$$CopilotToolMeta.java | Update fixture constructor call to include null metadata arg. |
| java/src/test/java/com/github/copilot/rpc/fixtures/OptionalParamTools$$CopilotToolMeta.java | Update fixture constructor calls to include null metadata arg. |
| java/src/test/java/com/github/copilot/rpc/fixtures/MultiReturnTools$$CopilotToolMeta.java | Update fixture constructor calls to include null metadata arg. |
| java/src/test/java/com/github/copilot/rpc/fixtures/InvocationAwareTools$$CopilotToolMeta.java | Update fixture constructor calls to include null metadata arg. |
| java/src/test/java/com/github/copilot/rpc/fixtures/DefaultValueTools$$CopilotToolMeta.java | Update fixture constructor call to include null metadata arg. |
| java/src/test/java/com/github/copilot/rpc/fixtures/DateTimeTools$$CopilotToolMeta.java | Update fixture constructor call to include null metadata arg. |
| java/src/test/java/com/github/copilot/rpc/fixtures/ArgCoercionTools$$CopilotToolMeta.java | Update fixture constructor call to include null metadata arg. |
| java/src/test/java/com/github/copilot/e2e/ErgonomicTestTools$$CopilotToolMeta.java | Update fixture constructor calls to include null metadata arg. |
Review details
- Files reviewed: 26/26 changed files
- Comments generated: 1
- Review effort level: Low
Add an optional, opaque `metadata` bag to tool definitions across all SDK languages and forward it verbatim over the session.create/resume RPC. This lets hosts attach namespaced metadata to tools without expanding the typed public contract; the runtime may recognize specific keys to inform host-specific behavior. Unknown keys are round-tripped untouched. Languages: nodejs (Tool.metadata + defineTool), python (Tool.metadata + define_tool), go (Tool.Metadata), rust (Tool.metadata + with_metadata), java (ToolDefinition.metadata + createWithMetadata), dotnet (CopilotToolOptions.Metadata + wire ToolDefinition.Metadata). Tests added per language for wire/serialization forwarding and omission when unset. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
belaltaher8
force-pushed
the
belaltaher8/tool-meta-passthrough
branch
from
July 8, 2026 15:18
6fdc349 to
0d575bc
Compare
- dotnet: change Metadata value type to IDictionary<string, JsonNode?> for
NativeAOT-safe serialization (CopilotToolOptions + wire ToolDefinition,
FromAIFunction cast, unit test); drop redundant [JsonPropertyName("metadata")]
since the Web camelCase policy already maps it; remove the <remarks> block
from the Metadata property.
- Reword metadata doc comments across nodejs/python/go/rust/java to describe
the bag opaquely without the SDK-vs-runtime/CLI distinction.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: bf2bf0dd-ec9f-42f5-a6e1-4f2a9e562d5f
…-passthrough # Conflicts: # python/test_client.py
edburns
requested changes
Jul 13, 2026
edburns
left a comment
Collaborator
There was a problem hiding this comment.
Please see this comment.
Address Java SME feedback so annotation-based tools reach parity with the programmatic API and existing constructor call sites keep compiling. - ToolDefinition: add a backward-compatible 7-arg constructor delegating to the canonical 8-arg with metadata=null. - CopilotTool: add metadata() plus nested MetadataEntry/MetadataValue/ MetadataFlag annotations (@target({})) with a shallow bool|str|flag-map representation, documenting the programmatic API for richer values. - CopilotToolProcessor: generate the metadata constructor argument (Map.<String, Object>of(...) with an explicit type witness) instead of a hardcoded null; null when no metadata is present. - Tests: processor generation cases (nested flags, absent, combined flags), ToolDefinition 7-arg/.metadata(...) copy/flag-chaining cases, and a fromObject metadata assertion; extend the SimpleTools fixture pair to emit a safeForTelemetry metadata map. - ADR-005: update the generated snippet to the 8-arg shape and document the @copilotTool(metadata = ...) syntax and emitted shape. Note: mvn verify / spotless:apply not run locally (no JDK/Maven in the dev environment); relies on PR CI. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: bf2bf0dd-ec9f-42f5-a6e1-4f2a9e562d5f
Reflow javadoc and wrap annotation/constructor args per the Eclipse formatter (mvn spotless:apply). No behavioral change. Verified locally: mvn spotless:check clean; ToolDefinitionTest (8), ToolDefinitionFromObjectTest (31), CopilotToolProcessorTest (37) all pass on JDK 26. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: bf2bf0dd-ec9f-42f5-a6e1-4f2a9e562d5f
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ab2c14cd-d2e1-4524-a6dc-e9c10899343c
edburns
requested changes
Jul 15, 2026
edburns
left a comment
Collaborator
There was a problem hiding this comment.
Please see #1864 (comment)
Do that and I'll give the green checkmark. Thanks.
test: assert null metadata arg in generated tool definition
edburns
approved these changes
Jul 15, 2026
SteveSandersonMS
approved these changes
Jul 15, 2026
SteveSandersonMS
left a comment
Contributor
There was a problem hiding this comment.
One minor comment about terminology in a comment (trivial fix), but beside that this looks great. Thanks!
…y state
Reword the 7-arg constructor's Javadoc to describe what the overload is (a
convenience constructor equivalent to the canonical one with metadata=null)
rather than its relationship to a specific change ("backward-compatible",
"retained so ... keep compiling after metadata was added"), which is only
meaningful in the context of the PR that introduced it.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: bf2bf0dd-ec9f-42f5-a6e1-4f2a9e562d5f
stephentoub
reviewed
Jul 15, 2026
HashMap serializes keys in a randomized order, unlike the sibling `parameters` field (IndexMap) and the other SDKs (nodejs/python insertion order, Go sorted). Switch the tool `metadata` bag to IndexMap<String, Value> so key order is deterministic and consistent, avoiding non-reproducible wire output. No new dependency; indexmap is already used by this struct. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: bf2bf0dd-ec9f-42f5-a6e1-4f2a9e562d5f
stephentoub
approved these changes
Jul 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add an optional
_metadatabag to theTooldefinition (anddefineTool) and forward it verbatim over the session.create/resume RPC. This lets hosts attach namespaced, opaque metadata to tools without expanding the typed public contract; unknown keys are round-tripped untouched.